﻿using Common.Tool.Models;
using Common.Tool.ControlTools;
using Common.Tool.FileTools;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace Common.Tool
{
    public class LogBase
    {
        public RichDocument document { get; set; }
        protected void CreateTestLogger(string sn, bool result,DateTime time)
        {
            log = new LoggerConfiguration().MinimumLevel.Debug()
                                                        .WriteTo.File($"logs/testlog/{time.ToString("yyyyMMdd")}/{sn}_{(result ? "OK" : "NG")}_{time.ToString("HHmmssfff")}.txt", outputTemplate: "{Message:lj}{NewLine}{Exception}", rollingInterval: RollingInterval.Infinite)
                                                        .CreateLogger();
        }
        protected ILogger log { get; set; }
        /// <summary>
        /// 插入一级标题
        /// </summary>
        protected void AppendTile1(string temp, string msg, DateTime? time = null)
        {
            time = time ?? DateTime.Now;
            document?.AppendTile1(temp, msg, time);
            LogHelper.Info(log, temp, msg, time);
        }
        /// <summary>
        /// 插入二级标题
        /// </summary>
        protected void AppendTile2(string temp, string msg, DateTime? time = null)
        {
            time = time ?? DateTime.Now;
            document?.AppendTile2(temp, msg, time);
            LogHelper.Info(log, temp, msg, time);
        }
        /// <summary>
        /// 插入信息
        /// </summary>
        protected void AppendInfo(string temp, string msg, DateTime? time = null)
        {
            time = time ?? DateTime.Now;
            document?.AppendInfo(temp, msg, time);
            LogHelper.Info(log, temp, msg, time);
        }
        /// <summary>
        /// 插入通信
        /// </summary>
        protected void AppendCommunication(string temp, string msg, DateTime? time = null)
        {
            time = time ?? DateTime.Now;
            document?.AppendCommunication(temp, msg, time);
            LogHelper.Info(log, temp, msg, time);
        }
        /// <summary>
        /// 插入提示
        /// </summary>
        protected void AppendTip(string temp, string msg, DateTime? time = null)
        {
            time = time ?? DateTime.Now;
            document?.AppendTip(temp, msg, time);
            LogHelper.Info(log, temp, msg, time);
        }
        /// <summary>
        /// 插入结果
        /// </summary>
        protected void AppendResult(string temp, string msg, DateTime? time = null)
        {
            time = time ?? DateTime.Now;
            document?.AppendResult(temp, msg, time);
            LogHelper.Info(log, temp, msg, time);
        }
        /// <summary>
        /// 插入错误
        /// </summary>
        protected void AppendErr(string temp, string msg, Exception ex = null, DateTime? time = null)
        {
            time = time ?? DateTime.Now;
            document?.AppendErr(temp, msg, time);
            LogHelper.Error(log, temp, msg, ex, time);
        }
    }
}
